{% if en %}
<div role="tabpanel" class="tab-pane config-section" id="email">
    <form method="POST" autocomplete="new-password" class="w-100">
        <h5>Email Content</h5>
        <small class="form-text text-muted">
            Customize CTFd emails with <a href="https://docs.ctfd.io/docs/settings/emails/#email-content" target="_blank">predefined variables</a> and custom content
        </small>
        <ul class="nav nav-tabs mt-3" role="tablist">
            <li class="nav-item active">
                <a class="nav-link active" href="#confirmation-email-tab" role="tab" data-toggle="tab">
                    Confirmation
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#account-details-email-tab" role="tab" data-toggle="tab">Account Details</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#password-reset-email-tab" role="tab" data-toggle="tab">Password Reset</a>
            </li>
        </ul>

        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="confirmation-email-tab">
                <div class="form-group">
                    <label class="pt-3">
                        Account Registration<br>
                        <small class="form-text text-muted">
                            Email sent to users after they've registered their account entirely
                        </small>
                    </label>
                    <div>
                        <label>
                            Subject
                        </label>
                        <input class="form-control" id='successful_registration_email_subject' name='successful_registration_email_subject' type='text'
                               value="{{ successful_registration_email_subject or ''}}">
                        <label>
                            Body
                        </label>
                        <textarea class="form-control" type="text" id="successful_registration_email_body" name="successful_registration_email_body"
                                  rows="5">{{ successful_registration_email_body or '' }}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="pt-3">
                        Account Confirmation<br>
                        <small class="form-text text-muted">
                            Email sent to users to confirm their account
                        </small>
                    </label>
                    <div>
                        <label>
                            Subject
                        </label>
                        <input class="form-control" id='verification_email_subject' name='verification_email_subject' type='text' value="{{ verification_email_subject or ''}}">
                        <label>
                            Body
                        </label>
                        <textarea class="form-control" type="text" id="verification_email_body" name="verification_email_body"
                                  rows="5">{{ verification_email_body or '' }}</textarea>
                    </div>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane" id="account-details-email-tab">
                <div class="form-group">
                    <label class="pt-3">
                        New Account Details<br>
                        <small class="form-text text-muted">
                            Email sent to new users (created by an admin) with their initial account details
                        </small>
                    </label>
                    <div>
                        <label>
                            Subject
                        </label>
                        <input class="form-control" id='user_creation_email_subject' name='user_creation_email_subject' type='text'
                               value="{{ user_creation_email_subject or ''}}">
                        <label>
                            Body
                        </label>
                        <textarea class="form-control" type="text" id="user_creation_email_body" name="user_creation_email_body"
                                  rows="5">{{ user_creation_email_body or '' }}</textarea>
                    </div>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane" id="password-reset-email-tab">
                <div class="form-group">
                    <label class="pt-3">
                        Password Reset Request<br>
                        <small class="form-text text-muted">
                            Email sent whent a user requests a password reset
                        </small>
                    </label>
                    <div>
                        <label>
                            Subject
                        </label>
                        <input class="form-control" id='password_reset_subject' name='password_reset_subject' type='text'
                               value="{{ password_reset_subject or ''}}">
                        <label>
                            Body
                        </label>
                        <textarea class="form-control" type="text" id="password_reset_body" name="password_reset_body"
                                  rows="5">{{ password_reset_body or '' }}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="pt-3">
                        Password Reset Confirmation<br>
                        <small class="form-text text-muted">
                            Email sent whent a user successfully resets their password
                        </small>
                    </label>
                    <div>
                        <label>
                            Subject
                        </label>
                        <input class="form-control" id='password_change_alert_subject' name='password_change_alert_subject' type='text'
                               value="{{ password_change_alert_subject or ''}}">
                        <label>
                            Body
                        </label>
                        <textarea class="form-control" type="text" id="password_change_alert_body" name="password_change_alert_body"
                                  rows="5">{{ password_change_alert_body or '' }}</textarea>
                    </div>
                </div>
            </div>
        </div>

        <hr class="my-5">

        <h5>Email Server</h5>
        <small class="form-text text-muted">
            Change the email server used by CTFd to send email
            <a class="float-right" href="https://docs.ctfd.io/docs/settings/emails#email-server" target="_blank">
                <i class="far fa-question-circle pr-2"></i>
            </a>
        </small>
        <ul class="nav nav-tabs my-3" role="tablist">
            <li class="nav-item active">
                <a class="nav-link active" href="#mailserver" role="tab" data-toggle="tab">Mail
                    Server</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#mailgun" role="tab" data-toggle="tab">Mailgun</a>
            </li>
        </ul>

        <div class="form-group">
            <label>
                Mail From Address<br>
                <small class="form-text text-muted">
                    Email address used to send email
                </small>
            </label>
            <input class="form-control" id='mailfrom_addr' name='mailfrom_addr' type='text' {% if mailfrom_addr is defined and mailfrom_addr != None %}value="{{ mailfrom_addr }}"{% endif %}>
        </div>

        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="mailserver">

                <div class="form-group">
                    <label>
                        Mail Server Address<br>
                        <small class="form-text text-muted">
                            Mail Server Address
                        </small>
                    </label>
                    <input class="form-control" id='mail_server' name='mail_server' type='text'
                           {% if mail_server is defined and mail_server != None %}value="{{ mail_server }}"{% endif %}>
                </div>

                <div class="form-group">
                    <label>
                        Mail Server Port<br>
                        <small class="form-text text-muted">
                            Mail Server Port
                        </small>
                    </label>
                    <input class="form-control" id='mail_port' name='mail_port' type='text'
                           {% if mail_port is defined and mail_port != None %}value="{{ mail_port }}"{% endif %}>
                </div>
                <div class="form-check">
                    <label>
                        <input id="mail_useauth" name="mail_useauth" type="checkbox"
                               {% if mail_useauth %}checked{% endif %}>
                        Use Mail Server Username and Password
                    </label>
                </div>
                <div id="mail_username_password">
                    <div class="form-group">
                        <label>
                            Username<br>
                            <small class="form-text text-muted">
                                Mail Server Account Username
                            </small>
                        </label>
                        {% if mail_username is defined and mail_username != None %}
                        <label>
                            <sup class="form-text text-muted">A mail server username is currently set</sup>
                        </label>
                        {% endif %}
                        <input class="form-control" id='mail_username' name='mail_username' autocomplete='new-password' type='text'>
                    </div>
                    <div class="form-group">
                        <label for="mail_password">
                            Password<br>
                            <small class="form-text text-muted">
                                Mail Server Account Password
                            </small>
                        </label>
                        {% if mail_password is defined and mail_password != None %}
                        <label>
                            <sup class="form-text text-muted">An mail server password is currently set</sup>
                        </label>
                        {% endif %}
                        <input class="form-control" id='mail_password' name='mail_password' autocomplete='new-password' type='password'>
                    </div>
                    <sup>Uncheck setting and update to remove username and password</sup>
                    <br>
                    <br>
                </div>
                <div class="form-check">
                    <label>
                        <input id="mail_ssl" name="mail_ssl" type="checkbox" {% if mail_ssl %}checked{% endif %}>
                        TLS/SSL
                    </label>
                </div>
                <div class="form-check">
                    <label>
                        <input id="mail_tls" name="mail_tls" type="checkbox" {% if mail_tls %}checked{% endif %}>
                        STARTTLS
                    </label>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane" id="mailgun">
                <div class="alert alert-warning" role="alert">
                    Mailgun integration is deprecated! Please see your Mailgun account for SMTP credentials.
                </div>
                <div class="form-group">
                    <label>
                        Mailgun API Base URL<br>
                        <small class="form-text text-muted">
                            Mailgun API Base URL
                        </small>
                    </label>
                    <input class="form-control" id='mailgun_base_url' name='mailgun_base_url' type='text'
                           {% if mailgun_base_url is defined and mailgun_base_url != None %}value="{{ mailgun_base_url }}"{% endif %}>
                </div>
                <div class="form-group">
                    <label>
                        Mailgun API Key<br>
                        <small class="form-text text-muted">
                            Mailgun API Key
                        </small>
                    </label>
                    <input class="form-control" id='mailgun_api_key' name='mailgun_api_key' type='text'
                           {% if mailgun_api_key is defined and mailgun_api_key != None %}value="{{ mailgun_api_key }}"{% endif %}>
                </div>
            </div>
        </div>
        <button type="submit" class="btn btn-md btn-primary float-right">Update</button>
    </form>
</div>
{% else %}
<div role="tabpanel" class="tab-pane config-section" id="email">
    <form method="POST" autocomplete="new-password" class="w-100">
        <h5>电子邮件内容</h5>
        <small class="form-text text-muted">
            使用<a href="https://docs.ctfd.io/docs/settings/emails/#email-content" target="_blank">预定义变量</a>和自定义内容自定义 CTFd 电子邮件
        </small>
        <ul class="nav nav-tabs mt-3" role="tablist">
            <li class="nav-item active">
                <a class="nav-link active" href="#confirmation-email-tab" role="tab" data-toggle="tab">
                    确认邮件
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#account-details-email-tab" role="tab" data-toggle="tab">账户详情</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#password-reset-email-tab" role="tab" data-toggle="tab">重置密码</a>
            </li>
        </ul>

        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="confirmation-email-tab">
                <div class="form-group">
                    <label class="pt-3">
                        账户注册<br>
                        <small class="form-text text-muted">
                            用户注册帐户后发送给他们的电子邮件
                        </small>
                    </label>
                    <div>
                        <label>
                            主题
                        </label>
                        <input class="form-control" id='successful_registration_email_subject' name='successful_registration_email_subject' type='text'
                               value="{{ successful_registration_email_subject or ''}}">
                        <label>
                            内容
                        </label>
                        <textarea class="form-control" type="text" id="successful_registration_email_body" name="successful_registration_email_body"
                                  rows="5">{{ successful_registration_email_body or '' }}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="pt-3">
                        账户确认<br>
                        <small class="form-text text-muted">
                            发送给用户的电子邮件以确认其注册了帐户
                        </small>
                    </label>
                    <div>
                        <label>
                            主题
                        </label>
                        <input class="form-control" id='verification_email_subject' name='verification_email_subject' type='text' value="{{ verification_email_subject or ''}}">
                        <label>
                            内容
                        </label>
                        <textarea class="form-control" type="text" id="verification_email_body" name="verification_email_body"
                                  rows="5">{{ verification_email_body or '' }}</textarea>
                    </div>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane" id="account-details-email-tab">
                <div class="form-group">
                    <label class="pt-3">
                        新帐户详细信息<br>
                        <small class="form-text text-muted">
                            发送给新用户（由管理员创建）的电子邮件及其初始帐户详细信息
                        </small>
                    </label>
                    <div>
                        <label>
                            主题
                        </label>
                        <input class="form-control" id='user_creation_email_subject' name='user_creation_email_subject' type='text'
                               value="{{ user_creation_email_subject or ''}}">
                        <label>
                            内容
                        </label>
                        <textarea class="form-control" type="text" id="user_creation_email_body" name="user_creation_email_body"
                                  rows="5">{{ user_creation_email_body or '' }}</textarea>
                    </div>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane" id="password-reset-email-tab">
                <div class="form-group">
                    <label class="pt-3">
                        重置密码请求<br>
                        <small class="form-text text-muted">
                            用户请求重置密码时发送的电子邮件
                        </small>
                    </label>
                    <div>
                        <label>
                            主题
                        </label>
                        <input class="form-control" id='password_reset_subject' name='password_reset_subject' type='text'
                               value="{{ password_reset_subject or ''}}">
                        <label>
                            内容
                        </label>
                        <textarea class="form-control" type="text" id="password_reset_body" name="password_reset_body"
                                  rows="5">{{ password_reset_body or '' }}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="pt-3">
                        密码重置确认<br>
                        <small class="form-text text-muted">
                            用户成功重置密码时发送的电子邮件
                        </small>
                    </label>
                    <div>
                        <label>
                            主题
                        </label>
                        <input class="form-control" id='password_change_alert_subject' name='password_change_alert_subject' type='text'
                               value="{{ password_change_alert_subject or ''}}">
                        <label>
                            内容
                        </label>
                        <textarea class="form-control" type="text" id="password_change_alert_body" name="password_change_alert_body"
                                  rows="5">{{ password_change_alert_body or '' }}</textarea>
                    </div>
                </div>
            </div>
        </div>

        <hr class="my-5">

        <h5>电子邮件服务器</h5>
        <small class="form-text text-muted">
            更改 CTFd 用于发送电子邮件的电子邮件服务器
            <a class="float-right" href="https://docs.ctfd.io/docs/settings/emails#email-server" target="_blank">
                <i class="far fa-question-circle pr-2"></i>
            </a>
        </small>
        <ul class="nav nav-tabs my-3" role="tablist">
            <li class="nav-item active">
                <a class="nav-link active" href="#mailserver" role="tab" data-toggle="tab">邮件服务器</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#mailgun" role="tab" data-toggle="tab">Mailgun</a>
            </li>
        </ul>

        <div class="form-group">
            <label>
                邮件发件人地址<br>
                <small class="form-text text-muted">
                    用于发送电子邮件的电子邮件地址
                </small>
            </label>
            <input class="form-control" id='mailfrom_addr' name='mailfrom_addr' type='text' {% if mailfrom_addr is defined and mailfrom_addr != None %}value="{{ mailfrom_addr }}"{% endif %}>
        </div>

        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="mailserver">

                <div class="form-group">
                    <label>
                        邮件服务器地址<br>
                        <small class="form-text text-muted">
                            邮件服务器地址
                        </small>
                    </label>
                    <input class="form-control" id='mail_server' name='mail_server' type='text'
                           {% if mail_server is defined and mail_server != None %}value="{{ mail_server }}"{% endif %}>
                </div>

                <div class="form-group">
                    <label>
                        邮件服务器端口<br>
                        <small class="form-text text-muted">
                            邮件服务器端口
                        </small>
                    </label>
                    <input class="form-control" id='mail_port' name='mail_port' type='text'
                           {% if mail_port is defined and mail_port != None %}value="{{ mail_port }}"{% endif %}>
                </div>
                <div class="form-check">
                    <label>
                        <input id="mail_useauth" name="mail_useauth" type="checkbox"
                               {% if mail_useauth %}checked{% endif %}>
                        使用邮件服务器用户名和密码
                    </label>
                </div>
                <div id="mail_username_password">
                    <div class="form-group">
                        <label>
                            用户名<br>
                            <small class="form-text text-muted">
                                邮件服务器帐户名
                            </small>
                        </label>
                        {% if mail_username is defined and mail_username != None %}
                        <label>
                            <small class="form-text text-muted" style="color: red">当前已设置邮件服务器用户名(已隐藏)</small>
                        </label>
                        {% endif %}
                        <input class="form-control" id='mail_username' name='mail_username' autocomplete='new-password' type='text'>
                    </div>
                    <div class="form-group">
                        <label for="mail_password">
                            密码<br>
                            <small class="form-text text-muted">
                                邮件服务器密码
                            </small>
                        </label>
                        {% if mail_password is defined and mail_password != None %}
                        <label>
                            <small class="form-text text-muted" style="color: red">当前已设置邮件服务器密码(已隐藏)</small>
                        </label>
                        {% endif %}
                        <input class="form-control" id='mail_password' name='mail_password' autocomplete='new-password' type='password'>
                    </div>
                    <sup>取消选中设置并点击更新以删除用户名和密码</sup>
                    <br>
                    <br>
                </div>
                <div class="form-check">
                    <label>
                        <input id="mail_ssl" name="mail_ssl" type="checkbox" {% if mail_ssl %}checked{% endif %}>
                        TLS/SSL
                    </label>
                </div>
                <div class="form-check">
                    <label>
                        <input id="mail_tls" name="mail_tls" type="checkbox" {% if mail_tls %}checked{% endif %}>
                        STARTTLS
                    </label>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane" id="mailgun">
                <div class="alert alert-warning" role="alert">
                    Mailgun 集成已弃用！ 请查看您的 Mailgun 帐户以获取 SMTP 凭据。
                </div>
                <div class="form-group">
                    <label>
                        Mailgun API URL<br>
                        <small class="form-text text-muted">
                            Mailgun API URL
                        </small>
                    </label>
                    <input class="form-control" id='mailgun_base_url' name='mailgun_base_url' type='text'
                           {% if mailgun_base_url is defined and mailgun_base_url != None %}value="{{ mailgun_base_url }}"{% endif %}>
                </div>
                <div class="form-group">
                    <label>
                        Mailgun API 密钥<br>
                        <small class="form-text text-muted">
                            Mailgun API 密钥
                        </small>
                    </label>
                    <input class="form-control" id='mailgun_api_key' name='mailgun_api_key' type='text'
                           {% if mailgun_api_key is defined and mailgun_api_key != None %}value="{{ mailgun_api_key }}"{% endif %}>
                </div>
            </div>
        </div>
        <button type="submit" class="btn btn-md btn-primary float-right">更新</button>
    </form>
</div>
{% endif %}

